local Msg = require("core.Msg")
local FuliConfig = require("excel.Fuli")
local FuliDefine = require("fuli.FuliDefine")
local LoginLogic = require("fuli.LoginLogic")
local FindCowryLogic = require("fuli.FindCowryLogic")
local InvestLogic = require("fuli.InvestLogic")
local OnlineLogic = require("fuli.OnlineLogic")
local SignLogic = require("fuli.SignLogic")
local CowryBagLogic = require("fuli.CowryBagLogic")
local FirstPayLogic = require("fuli.FirstPayLogic")
local ActivityLogicL = require("activity.ActivityLogicL")
local LvLogic = require("fuli.LvLogic")

function checkNeedSend(human, index)
  if FuliDefine.FULI_TYPE_INVEST == index then
    return not InvestLogic.checkGetAll(human)
  end
  return true
end

function sendFuliList(human)
  local sendMsg = Msg.gc.GC_FULI_LIST
  local len = 0
  for i=1, #FuliConfig.list do
    if checkNeedSend(human, i) then
      len = len + 1
      sendMsg.list[len].page = i
      sendMsg.list[len].name = FuliConfig.list[i].detail
    end
  end
  sendMsg.list[0] = len
  Msg.send(sendMsg, human.fd)
end

function CG_FULI_GET_PAGE_LIST(human, msg)
  if FuliDefine.FULI_TYPE_LOGIN == msg.page then
    LoginLogic.getRewardList(human)
  elseif FuliDefine.FULI_TYPE_SIGN == msg.page then
    SignLogic.getRewardList(human)
  elseif FuliDefine.FULI_TYPE_INVEST == msg.page then
    InvestLogic.getRewardList(human)
  elseif FuliDefine.FULI_TYPE_ONLINE == msg.page then
    OnlineLogic.getRewardList(human)
    checkShowTips(human)
  elseif FuliDefine.FULI_TYPE_COWRY == msg.page then
    FindCowryLogic.getRewardList(human)
  elseif FuliDefine.FULI_TYPE_LV == msg.page then
    LvLogic.getLvRewardList(human)
  end  
end

function CG_FULI_GET_REWARD(human, msg)
  if FuliDefine.FULI_TYPE_LOGIN == msg.page then
    LoginLogic.getReward(human, msg.index)
  elseif FuliDefine.FULI_TYPE_SIGN == msg.page then
    SignLogic.getReward(human, msg.index, msg.isVipReward)
  elseif FuliDefine.FULI_TYPE_INVEST == msg.page then
    InvestLogic.getReward(human, msg.index)
  elseif FuliDefine.FULI_TYPE_ONLINE == msg.page then
    OnlineLogic.getReward(human, msg.index, msg.isVipReward)    
  elseif FuliDefine.FULI_TYPE_LV == msg.page then
    LvLogic.getLvReward(human, msg.index)
  elseif FuliDefine.FULI_TYPE_GROW == msg.page then
    LvLogic.getGrowReward(human, msg.index)
  end
end
--签到
function CG_FULI_SIGN(human, msg)
  SignLogic.sign(human, msg.day)
end
--购买投资
function CG_FULI_BUY_INVEST(human, msg)
  InvestLogic.invest(human, msg.rmb)
end

--寻宝
function CG_FULI_FIND_COWRY(human, msg)
  FindCowryLogic.findCowry(human, msg.type)
end

function CG_COWRY_BAG_SORT(human)
  CowryBagLogic.sortCowryBag(human)
end

function CG_COWRY_BAG_EXTRACT(human, msg)
  if msg.type == 0 then
    CowryBagLogic.extractOne(human, msg.index)
  else
    CowryBagLogic.extractALL(human)
  end
end

function CG_COWRY_BAG_SWAP(human, msg)
  CowryBagLogic.swapCowryBag(human, msg.srcIndex, msg.tarIndex)
end

function updateStatus(human)
  LoginLogic.updateStatus(human)
  SignLogic.updateStatus(human)
  OnlineLogic.updateStatus(human)
  FindCowryLogic.updateStatus(human)
  checkShowTips(human)
end

function onLvUp(human)
  InvestLogic.onLvUp(human)
  LvLogic.checkCanGetReward(human)
  checkShowTips(human)
end

function CG_FIRST_PAY_QUERY(human, msg)
  FirstPayLogic.query(human, msg.type)
end

function CG_FIRST_PAY_GET(human, msg)
  FirstPayLogic.get(human, msg.type)
end

function checkShowTips(human)
  local sendMsg = Msg.gc.GC_FULI_TIPS_ICON
  sendMsg.isShow[0] = 6
  sendMsg.isShow[1] = LoginLogic.checkShowTips(human)
  sendMsg.isShow[2] = SignLogic.checkShowTips(human)
  sendMsg.isShow[3] = InvestLogic.checkShowTips(human)
  sendMsg.isShow[4] = OnlineLogic.checkShowTips(human)
  sendMsg.isShow[5] = LvLogic.checkShowTips(human)
  sendMsg.isShow[6] = ActivityLogicL.checkShowTips(human)
  
  Msg.send(sendMsg, human.fd)
end
